﻿using PBO.Data;
using PBO.Game;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PBO.Game.BattleClass
{
    public partial class Battle
    {

        private double CalculateMovePower(Pokemon user, Pokemon target, Move selMove, BattleType selMoveType)
        {
            double num2 = Convert.ToDouble(selMove.Power);
#warning 滥用power判断
            if (num2 > 250)
            {
                num2 = 0.0;
            }
            switch (selMove.Data.AddEffect2)
            {
                case MoveAdditionalEffect.对象潜水伤害加倍:
                    if (target.BattleState.dive)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象变小伤害加倍:
                    if (target.BattleState.minimize)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象挖洞伤害加倍:
                    if (target.BattleState.dig)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象空中伤害加倍:
                    if (target.BattleState.fly)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.自身受到伤害威力加倍:
                    if (user.turnHurt.Count > 0)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.连续使用威力加倍:
                    if (user.BattleState.previousMove == selMove.Data.Id)
                    {
                        PokemonBattleState battleState = user.BattleState;
                        battleState.successContinAttackCounter++;
                    }
                    else
                    {
                        user.BattleState.successContinAttackCounter = 0;
                    }
                    num2 *= Math.Pow(2.0, (double)user.BattleState.successContinAttackCounter);
                    break;

                case MoveAdditionalEffect.较后攻击威力加倍:
                    if (target.BattleState.moved)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象受到伤害威力加倍:
                    if (target.turnHurt.Count > 0)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象HP低一半威力加倍:
                    if (target.HealthPower < (((double)target.MaxHp) / 2.0))
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.自身异常威力加倍:
                    if (((user.State == PokemonState.Burn) || (user.State == PokemonState.Paralysis)) || ((user.State == PokemonState.Poison) || (user.State == PokemonState.Toxin)))
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.天气球:
                    if (this.Ground.Weather != Weather.Normal)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象睡眠伤害加倍:
                    if (target.State == PokemonState.Sleep)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.对象麻痹伤害加倍:
                    if (target.State == PokemonState.Paralysis)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.呕吐:
                    {
                        num2 *= user.BattleState.StockpileCounter;
                        Pokemon pokemon = user;
                        pokemon.BattleState.StockpileCounter = 0;
                        pokemon.AbilityLvDownChanged(StatType.Def, user.BattleState.StockpileDefCounter, false);
                        pokemon.BattleState.StockpileDefCounter = 0;
                        pokemon.AbilityLvDownChanged(StatType.SpDef, user.BattleState.StockpileSDefCounter, false);
                        pokemon.BattleState.StockpileSDefCounter = 0;
                        pokemon = null;
                        break;
                    }
                case MoveAdditionalEffect.追击:
                    if (user.BattleState.pursuit)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.威力随对象体重变化:
                    {
                        double weight = target.Data.Weight;

                        if (weight < 10.0)
                        {
                            num2 = 20.0;
                        }
                        else
                        {
                            num2 = 40.0;
                            for (int i = 25; i <= 200; i *= 2)
                            {
                                if (weight > i)
                                    num2 += 20;
                                else
                                    break;
                            }
                        }
                        break;
                    }
                case MoveAdditionalEffect.螺旋球:
                    num2 = ((double)(0x19 * target.Speed)) / ((double)user.Speed);
                    num2 = Math.Max(2.0, num2);
                    num2 = Math.Min(150.0, num2);
                    break;

                case MoveAdditionalEffect.威力随剩余PP变化:
                    {
                        int[] TrumpCard_Power = { 200, 80, 60, 50, 40 };
                        int pP = Math.Min(5, selMove.PP);
                        num2 = TrumpCard_Power[pP - 1];
                        break;
                    }
                case MoveAdditionalEffect.威力随HP变化:
                    num2 = ((double)(150 * user.HealthPower)) / ((double)user.MaxHp);
                    break;

                case MoveAdditionalEffect.伤害随对象HP变化:
                    num2 = ((double)(120 * target.HealthPower)) / ((double)target.MaxHp);
                    break;

                case MoveAdditionalEffect.挣扎:
                    {
                        double num6 = ((double)user.HealthPower) / ((double)user.MaxHp);
                        if (num6 >= 0.042)
                        {
                            if (num6 < 0.105)
                            {
                                num2 = 150.0;
                            }
                            else if (num6 < 0.209)
                            {
                                num2 = 100.0;
                            }
                            else if (num6 < 0.355)
                            {
                                num2 = 80.0;
                            }
                            else if (num6 < 0.688)
                            {
                                num2 = 40.0;
                            }
                            else
                            {
                                num2 = 20.0;
                            }
                            break;
                        }
                        num2 = 200.0;
                        break;
                    }
                case MoveAdditionalEffect.滚动:
                    num2 = 30.0 * Math.Pow(2.0, (double)(user.BattleState.RollCounter - 1));
                    if (user.BattleState.defenseCurl)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.震级:
                    if (target.BattleState.dig)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.太阳光线:
                    if (((this.Ground.Weather == Weather.Rainy) || (this.Ground.Weather == Weather.SandStorm)) || (this.Ground.Weather == Weather.HailStorm))
                    {
                        num2 *= 0.5;
                    }
                    break;

                case MoveAdditionalEffect.雷电:
                    if (target.BattleState.fly)
                    {
                        num2 *= 2.0;
                    }
                    break;

                case MoveAdditionalEffect.掷物:
                    log.AppendMsg("bad", user.NickName, selMove.Data.Name);
                    //this.log.AppendText("该技能具体效果目前不明...");
                    return 0.0;

                case MoveAdditionalEffect.责罚:
                    {
                        int num3 = target.BattleState.AbilityLv.Get5D().Where(i => i > 0).Sum();
                        num2 = 60 + (20 * num3);
                        num2 = Math.Min(200, num2);
                        break;
                    }
            }
            if (((((user.GetSelTrait(false) == Trait.FlashFire) && user.BattleState.traitRaised) && (selMoveType == BattleType.Fire)) ||
                (((user.GetSelTrait(false) == Trait.Torrent) && (user.HealthPower < (((double)user.MaxHp) / 3.0))) && (selMoveType == BattleType.Water))) ||
                (((((user.GetSelTrait(false) == Trait.Overgrow) && (user.HealthPower < (((double)user.MaxHp) / 3.0))) && (selMoveType == BattleType.Grass)) ||
                (((user.GetSelTrait(false) == Trait.Swarm) && (user.HealthPower < (((double)user.MaxHp) / 3.0))) && (selMoveType == BattleType.Bug))) ||
                (((user.GetSelTrait(false) == Trait.Blaze) && (user.HealthPower < (((double)user.MaxHp) / 3.0))) && (selMoveType == BattleType.Fire))))
            {
                num2 *= 1.5;
            }
            else if (((user.GetSelTrait(false) == Trait.IronFist) && selMove.Punch) || ((user.GetSelTrait(false) == Trait.Reckless) && (((selMove.Data.AddEffect2 == MoveAdditionalEffect.伤害反弹三分一) || (selMove.Data.AddEffect2 == MoveAdditionalEffect.伤害反弹四分一)) || ((selMove.Data.AddEffect2 == MoveAdditionalEffect.双刃头槌) || (selMove.Data.AddEffect2 == MoveAdditionalEffect.攻击失败反弹一半)))))
            {
                num2 *= 1.2;
            }
            else if ((user.GetSelTrait(false) == Trait.Technician) && (num2 <= 60.0))
            {
                num2 *= 1.5;
            }
            if (user.GetItem(false) == Item.LifeOrb)
            {
                num2 *= 1.3;
            }
            else if ((user.GetItem(false) == Item.Metronome) && (user.BattleState.previousMove == selMove.Data.Id))
            {
                num2 *= 1.1;
            }
            if (selMove.Data.AddEffect1 == MoveAdditionalEffect.自爆)
            {
                num2 *= 2.0;
            }
            if (user.BattleState.meFirst)
            {
                num2 *= 1.5;
            }
            if (this.Ground.waterSport && (selMoveType == BattleType.Fire))
            {
                num2 *= 0.5;
            }
            if (this.Ground.mudSport && (selMoveType == BattleType.Electric))
            {
                num2 *= 0.5;
            }
            if (user.BattleState.charge && (selMoveType == BattleType.Electric))
            {
                num2 *= 2.0;
            }
            if ((((((((user.GetItem(false) == Item.Blackglasses) || (user.GetItem(false) == Item.DreadPlate)) && (selMoveType == BattleType.Dark)) ||
                (((user.GetItem(false) == Item.BlackBelt) || (user.GetItem(false) == Item.FistPlate)) && (selMoveType == BattleType.Fighting))) ||
                ((((user.GetItem(false) == Item.Silverpowder) || (user.GetItem(false) == Item.InsectPlate)) && (selMoveType == BattleType.Bug)) ||
                (((user.GetItem(false) == Item.Twistedspoon) || (user.GetItem(false) == Item.MindPlate)) && (selMoveType == BattleType.Psychic)))) ||
                (((((user.GetItem(false) == Item.HardStone) || (user.GetItem(false) == Item.StonePlate)) && (selMoveType == BattleType.Rock)) ||
                (((user.GetItem(false) == Item.PoisonBarb) || (user.GetItem(false) == Item.ToxicPlate)) && (selMoveType == BattleType.Poison))) ||
                ((((user.GetItem(false) == Item.SharpBeak) || (user.GetItem(false) == Item.SkyPlate)) && (selMoveType == BattleType.Flying)) ||
                (((user.GetItem(false) == Item.Nevermeltice) || (user.GetItem(false) == Item.IciclePlate)) && (selMoveType == BattleType.Ice))))) ||
                ((((((user.GetItem(false) == Item.SoftSand) || (user.GetItem(false) == Item.EarthPlate)) && (selMoveType == BattleType.Ground)) ||
                (((user.GetItem(false) == Item.SpellTag) || (user.GetItem(false) == Item.SpookyPlate)) && (selMoveType == BattleType.Ghost))) ||
                ((((user.GetItem(false) == Item.Magnet) || (user.GetItem(false) == Item.ZapPlate)) && (selMoveType == BattleType.Electric)) ||
                (((user.GetItem(false) == Item.MysticWater) || (user.GetItem(false) == Item.SplashPlate)) && (selMoveType == BattleType.Water)))) ||
                (((((user.GetItem(false) == Item.MiracleSeed) || (user.GetItem(false) == Item.MeadowPlate)) && (selMoveType == BattleType.Grass)) ||
                (((user.GetItem(false) == Item.MetalCoat) || (user.GetItem(false) == Item.IronPlate)) && (selMoveType == BattleType.Steel))) ||
                (((((user.GetItem(false) == Item.Charcoal) || (user.GetItem(false) == Item.FlamePlate)) && (selMoveType == BattleType.Fire)) ||
                (((user.GetItem(false) == Item.DragonFang) || (user.GetItem(false) == Item.DracoPlate)) && (selMoveType == BattleType.Dragon))) ||
                ((user.GetItem(false) == Item.SilkScarf) && (selMoveType == BattleType.Normal)))))) ||
                ((((user.GetItem(false) == Item.AdamantOrb) && (user.Data.Number == 0x1e3)) && ((selMoveType == BattleType.Dragon) || (selMoveType == BattleType.Steel))) ||
                ((((user.GetItem(false) == Item.LustrousOrb) && (user.Data.Number == 0x1e4)) && ((selMoveType == BattleType.Dragon) || (selMoveType == BattleType.Water))) ||
                (((user.GetItem(false) == Item.GriseousOrb) && (user.Data.Number == 0x1e7)) && ((selMoveType == BattleType.Dragon) || (selMoveType == BattleType.Ghost))))))
            {
                return (num2 * 1.2);
            }
            if (((user.GetItem(false) != Item.MuscleBand) || (selMove.Data.Category != MoveCategory.物理)) && ((user.GetItem(false) != Item.WiseGlasses) || (selMove.Data.Category != MoveCategory.特殊)))
            {
                return num2;
            }
            return (num2 * 1.1);
        }
    }
}
